home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / in_multiplex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  14.8 KB  |  419 lines

  1. #ifndef    lint
  2. static char SccsId[]= "@(#)in_multiplex.c    V1.18    3/13/95";
  3. #endif
  4. /*
  5. |    file name - in_multiplex.c
  6. |===================================================================
  7. |
  8. |    This program shows how to create the Multiplexor Interaction
  9. |       Handler.
  10. |
  11. |       The multiplexor is a menu in which each selection activates
  12. |       a different input object. The activated input object is
  13. |       displayed in a shared input area defined by the layout
  14. |       file for the multiplexor.  In this example, the user may
  15. |    select between two different slider input objects. The
  16. |    slider input objects control the update of the dial graph.
  17. |
  18. |    To quit the example use the <q>, <Q> keys or the right mouse
  19. |    button.
  20. |
  21. |===================================================================
  22. */
  23. #include <windows.h>
  24. /*
  25.  *  DV-Tools header files
  26.  */
  27. #include "std.h"                /* <stdio.h> etc., scalar & macro definitions */
  28. #include "dvstd.h"              /* public types & constants */
  29. #include "dvtools.h"            /* constants used by T routines */
  30. #include "dvGR.h"               /* constants used by window mgt & GR routines */
  31. #include "VOstd.h"              /* constants used by VO & VOob routines */
  32. #include "Tfundecl.h"           /* T routines (screens, drawports & views) */
  33. #include "VOfundecl.h"          /* VO routines (objects) */
  34. #include "VUerfundecl.h"        /* VUer routines (event handling routines) */
  35. #include "VPfundecl.h"          /* VP routines (put info for dgp & vdp) */
  36. #include "VGfundecl.h"          /* VG routines (get info for dgp & vdp) */
  37.  
  38. /* Constants */
  39. #define  DVPATH            (char *)NULL
  40. #define  DISPFORMS_STB     (char *)NULL
  41. #define  DVDEVICE          (char *)NULL
  42. #define  DVCOLORTABLE      (char *)NULL
  43. #define  VIEW_NAME       "multiplex.v"
  44. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  45. #define  DRAWING_VIEWPORT  (RECTANGLE *)NULL
  46.  
  47. /* Define buffers for input objects */
  48. float MultiValue = 0.0,         /* multiplexor buffer */
  49.   SliderValues[2] = {3.0, 0.0}; /* slider buffers */
  50.  
  51. /* Define interaction handlers */
  52. GLOBALREF INHANDLER VNmultiplexor, VNslider;
  53.  
  54. /*
  55.  *   MAIN PROGRAM
  56.  */
  57. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, 
  58.                      LPSTR lpCmdLine, int nCmdShow )
  59. {
  60.   INT argc = 0;
  61.   CHAR **argv;
  62.  
  63.   /*
  64.    *  program arguments
  65.    *    argv[1] - display device (default is DVDEVICE)
  66.    */
  67.  
  68.   /* Define & initialize device name and view filename */
  69.   char *device_name = DVDEVICE; /* default device name */
  70.   char *view_name = VIEW_NAME;  /* default view name */
  71.  
  72.   /* Define display variables */
  73.   OBJECT screen;                /* display device, the window */
  74.   DRAWPORT drawport;            /* how & where to display picture, picture frame */
  75.   VIEW view;                    /* picture representation of the view file */
  76.  
  77.   /* Control loop variables */
  78.   OBJECT location,              /* the event representation */
  79.     event_status;               /* how the event handler has used the location event */
  80.  
  81.   /* Input object related variables */
  82.   ATTRIBUTES Attributes;        /* attribute structure */
  83.   VIEW TemplateView;            /* template view */
  84.   OBJECT TemplateDrawing;       /* drawing object of template view */
  85.   OBJECT LLcorner,              /* lower left pt of input obj */
  86.     URcorner,                   /* upper right pt of input obj */
  87.     MultiInput,                 /* multiplexor input obj */
  88.     MultiTech,                  /* multiplexor input technique obj */
  89.     SliderInput[2],             /* embedded input objects */
  90.     SliderTech[2];              /* embedded input objs technique objs */
  91.   VARDESC Vdps[3];              /* variable descriptors for input objs */
  92.  
  93.   /* Graph related variables */
  94.   OBJECT dial_graph;            /* graph object */
  95.   DATAGROUP dgp;                /* pointer to data group structure */
  96.   VARDESC vdp;                  /* variable descriptor */
  97.  
  98.   /* Other variables */
  99.   int Quit = NO;                /* flag to quit program */
  100.   int i;                        /* counter */
  101.  
  102.   /*--------------------
  103.    *  Initialization
  104.    *
  105.    *   TInit:  perform the initialization of DV-Tools
  106.    *           TInit reads your configuration file and any
  107.    *           environment variables or logical names set.
  108.    */
  109.   make_argv(&argc,&argv,GetCommandLine());
  110.   TInit( DVPATH, DISPFORMS_STB );
  111.  
  112.   /*
  113.    *   TscOpenSet: open a device as a screen object using
  114.    *               specified attributes
  115.    *   TscErase:   erase the entire screen in the default
  116.    *               background color
  117.    *
  118.    *   Set exposure block to YES to insure the window
  119.    *   is ready for drawing when TdpDraw is called.
  120.    */
  121.   if (argc > 1)
  122.     device_name = argv[1];
  123.   screen = TscOpenSet (device_name, DVCOLORTABLE,
  124.                        V_X_EXPOSURE_BLOCK, YES,
  125.                        V_ACTIVE_CURSOR, V_END_OF_LIST);
  126.   if (!screen)
  127.     {
  128.       printf ("Must specify device on command line or");
  129.       printf (" in DataViews configuration file.\n");
  130.       S_EXIT (EXIT_ERR);
  131.     }
  132.  
  133.   /*
  134.    *   VOscWinEventMask:  sets the screen's window event mask
  135.    */
  136.   VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS |
  137.                             V_MOTIONNOTIFY | V_EXPOSE | V_RESIZE,
  138.             (ULONG) 0);
  139.  
  140.   /*
  141.    *   TviLoad:   Load a view in from a file, either a
  142.    *              user supplied view or default view file play.v
  143.    *   TdpCreate: Create a DV-Tools window, a drawport.
  144.    *              The drawport is attached to the screen object
  145.    *              specified while view specifies the view to be
  146.    *              displayed on the screen.
  147.    */
  148.   view = TviLoad (view_name);
  149.   if (!view)
  150.     {
  151.       printf ("Could not load view from file ");
  152.       printf ("%s.\n", view_name);
  153.       S_EXIT (EXIT_ERR);
  154.     }
  155.   drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
  156.  
  157.   /*
  158.    *  VOdgGetDgp:   Returns pointer to the data group structure
  159.    *  VGdgvd:       Gets the address or number of vdps from the data group
  160.    *  TvdPutBuffer: Set a new variable descriptor buffer
  161.    *
  162.    *  Rebind the graphs variables to the same buffers that will be
  163.    *  controlled by the sliders in the multiplexor.
  164.    */
  165.   dial_graph = TdrGetNamedObject (TviGetDrawing (view), "dial_graph");
  166.   dgp = VOdgGetDgp (dial_graph);
  167.   for (i = 1; i <= (int) VGdgvd (dgp, 0); i++)
  168.     {
  169.       vdp = VGdgvd (dgp, i);
  170.       TvdPutBuffer (vdp, (ADDRESS) &SliderValues[i - 1]);
  171.     }
  172.  
  173.   /*
  174.    *   VUerPutKeys:  Sets the key-action bindings
  175.    *                 define the left mouse button as the select
  176.    *                 keys while the right mouse button will
  177.    *                 represent the cancel key.
  178.    */
  179.   VUerPutKeys (SELECT_KEYS, "\001");
  180.   VUerPutKeys (CANCEL_KEYS, "\003");
  181.  
  182.   /*
  183.    *   VOuAtInit:  Sets all attribute fields to EMPTY_FIELD.
  184.    *   VOcoCreate: Create a color or RGB object
  185.    *   VOptCreate: Create a point object
  186.    *
  187.    *   Initialize the attributes structure and fill the fields
  188.    *   representing foreground and background color. Also,
  189.    *   create the control points to be used by the multiplexor
  190.    *   input object and its embedded input objects
  191.    */
  192.   VOuAtInit (&Attributes);
  193.   Attributes.foreground_color = VOcoCreate (COLOR_NAME, "white");
  194.   Attributes.background_color = VOcoCreate (COLOR_NAME, "black");
  195.   LLcorner = VOptCreate (WORLD_COORDINATES, -12000, -12000, (OBJECT) NULL);
  196.   URcorner = VOptCreate (WORLD_COORDINATES, 11000, -4200, (OBJECT) NULL);
  197.  
  198.   /*
  199.    *   VOinCreate:  Create an input object
  200.    *
  201.    *   Create the multiplexor and 2 embedded slider input objects.
  202.    */
  203.   MultiInput = VOinCreate (LLcorner, URcorner, &Attributes);
  204.   SliderInput[0] = VOinCreate (LLcorner, URcorner, &Attributes);
  205.   SliderInput[1] = VOinCreate (LLcorner, URcorner, &Attributes);
  206.  
  207.   /*
  208.    *   VPvdcreate:   Create a variable descriptor
  209.    *   VPvd_drange:  Sets the range in doubles.
  210.    *   VPvdvarname:  Specifies the name of a variable
  211.    *
  212.    *   Create the variable descriptors for each of the input objects.
  213.    *   The variable descriptors will be bound to program variables.
  214.    */
  215.   Vdps[0] = VPvdcreate ((ADDRESS) & MultiValue, V_F_TYPE);
  216.   VPvd_drange (Vdps[0], (double)0.0, (double)1.0);
  217.   Vdps[1] = VPvdcreate ((ADDRESS) & SliderValues[0], V_F_TYPE);
  218.   VPvdvarname (Vdps[1], "Slider1");
  219.   VPvd_drange (Vdps[1], (double)0.0, (double)18.0);
  220.   Vdps[2] = VPvdcreate ((ADDRESS) & SliderValues[1], V_F_TYPE);
  221.   VPvdvarname (Vdps[2], "Slider2");
  222.   VPvd_drange (Vdps[2], (double)0.0, (double)18.0);
  223.  
  224.   /*
  225.    *   VOinPutVarList:  Sets the variable descriptor list
  226.    *
  227.    *   Set the vdp list for each of the input objects.
  228.    */
  229.   VOinPutVarList (SliderInput[0], (ADDRESS *) Vdps[1], (int)1);
  230.   VOinPutVarList (SliderInput[1], (ADDRESS *) Vdps[2], (int)1);
  231.   VOinPutVarList (MultiInput, (ADDRESS *) Vdps, (int)3);
  232.  
  233.   /*
  234.    *  VOitCreate:    Create an input technique object
  235.    *  VOinTechnique: Sets the input technique to be used for this
  236.    *                 input object.
  237.    *
  238.    *  Load in the layout views which will define the appearance of
  239.    *  the embedded slider input objects. The drawing object of the
  240.    *  view is obtained and attached to the input technique.  The
  241.    *  input technique defines the type of input object based on
  242.    *  the interaction handler and the appearance is defined by
  243.    *  the layout file.
  244.    */
  245.   TemplateView = TviLoad ("DefSlider.lay");
  246.   TemplateDrawing = TviGetDrawing (TemplateView);
  247.   for (i = 0; i <= 1; i++)
  248.     {
  249.       SliderTech[i] = VOitCreate (VNslider, TemplateDrawing);
  250.       VOinTechnique (SliderInput[i], SliderTech[i]);
  251.     }
  252.   TviDestroy (TemplateView);
  253.  
  254.   /*
  255.    *  Create the input technique object for the multiplexor input
  256.    *  object. Attach the input object and technique together.
  257.    *  Also, attach the slider input objects to the multiplexor.
  258.    */
  259.   TemplateView = TviLoad ("Multiplexr.lay");
  260.   TemplateDrawing = TviGetDrawing (TemplateView);
  261.   MultiTech = VOitCreate (VNmultiplexor, TemplateDrawing);
  262.   TviDestroy (TemplateView);
  263.   VOinTechnique (MultiInput, MultiTech);
  264.   VOitPutList (MultiTech, OBJECT_LIST, (ADDRESS) SliderInput, 2);
  265.  
  266.   /*
  267.    *  Define key bindings for the multiplexor.  The done keys and
  268.    *  select keys are bound to the same key binding. This is the
  269.    *  recommended practice and is similar to the menu input object.
  270.    */
  271.   VOitPutKeys (MultiTech, SELECT_KEYS, "\001");
  272.   VOitKeyOrigin (MultiTech, SELECT_KEYS, LOCAL_KEYS);
  273.   VOitPutKeys (MultiTech, DONE_KEYS, "\001");
  274.   VOitKeyOrigin (MultiTech, DONE_KEYS, LOCAL_KEYS);
  275.  
  276.   /*
  277.    *  VOdrObAdd:  Adds an object to the drawing
  278.    *
  279.    *  Add the multiplexor input object to the view's drawing.
  280.    *  The object will be drawn, updated and redrawn whenever
  281.    *  these actions are performed on the drawport containing
  282.    *  this view.
  283.    */
  284.    VOdrObAdd (TviGetDrawing (view), MultiInput);
  285.  
  286.   /*
  287.    *  TscErase:  erase the entire screen in the default
  288.    *             background color
  289.    *  TdpDraw:   Draw the contents of a drawport
  290.    *
  291.    *  Erase the screen and draw the drawport.
  292.    */
  293.    TscErase (screen);
  294.    TdpDraw (drawport);
  295.  
  296.   /*--------------------
  297.    *   Control loop
  298.    *
  299.    *   Poll the event queue for window events specified by the
  300.    *   window mask.  Handle each of the events as they happen.
  301.    *   Events occurring within input objects will be handled
  302.    *   through the event request handler VUerHandleLocEvent.
  303.    *   Stop when the user selects "q|Q" or the right mouse button.
  304.    */
  305.   FOREVER
  306.   {
  307.     /*
  308.      *  VOloWinEventPoll:   Poll for the next window event.
  309.      *
  310.      *  VUerHandleLocEvent: Service the event. This routine will check
  311.      *                      if the event is used by any input objects
  312.      *                      that may be in the view.
  313.      */
  314.     location = VOloWinEventPoll (V_WAIT);
  315.     event_status = VUerHandleLocEvent (location);
  316.  
  317.     /*
  318.      * If the return value of VUerHandleLocEvent is INPUT_UNUSED
  319.      * then check for keypress or buttonpress events which
  320.      * represent one of the exit keys.
  321.      */
  322.     if (event_status == INPUT_UNUSED)
  323.       {
  324.         /*
  325.          *  VOloType:  returns the type of event.  These types
  326.          *             match event types specified in VOscWinEventMask.
  327.          */
  328.         switch (VOloType (location))
  329.           {
  330.           case V_EXPOSE:
  331.             /*
  332.              *  VOloRegion:  Returns a rectangle representing the
  333.              *               exposed region on the screen.
  334.              *  TscRedraw:   After erasing, redraws all the drawports
  335.              *               in the screen.
  336.              *  A portion of the window has been exposed and needs
  337.              *  to be redrawn.
  338.              */
  339.              TscRedraw (screen, VOloRegion (location));
  340.             break;
  341.  
  342.           case V_RESIZE:
  343.             /*
  344.              *  TscReset:  Resets all screen drawports after
  345.              *             window resizing
  346.              *  The window size has been changed.
  347.              */
  348.              TscReset (screen);
  349.             break;
  350.  
  351.           case V_KEYPRESS:
  352.             /*
  353.              *  Check key selected.
  354.              *  VOloKeySym:  Returns the key symbol value of the
  355.              *               location object
  356.              *
  357.              *  If the key symbol represents the characters 'q'
  358.              *  or 'Q' then quit the program.
  359.              */
  360.             switch (VOloKeySym (location))
  361.               {
  362.               case 'q':
  363.               case 'Q':
  364.                 Quit = YES;
  365.                 break;
  366.               }
  367.  
  368.           case V_BUTTONPRESS:
  369.             /*
  370.              *  Check button selected.
  371.              *  VOloButton:  Returns the button that was pressed
  372.              *
  373.              *  The right mouse button exits the program.
  374.              */
  375.             switch (VOloButton (location))
  376.               {
  377.               case 3:
  378.                 Quit = YES;
  379.                 break;
  380.  
  381.               default:
  382.                 break;
  383.               }
  384.             break;
  385.  
  386.           default:
  387.             break;
  388.           }
  389.       }
  390.     else
  391.       /*
  392.        *  TdpDrawNext:  Updates all dynamic objects
  393.        *
  394.        *  Update graph object based on change to sliders
  395.        */
  396.        TdpDrawNext (drawport);
  397.  
  398.     /* exit the program */
  399.     if (Quit == YES)
  400.       break;
  401.   }
  402.  
  403.   /*--------------------
  404.    *   Termination
  405.    *
  406.    *   TscErase:              Erase the screen object
  407.    *   TdpDestroy:            Destroy the drawport,
  408.    *   TviDestroy:            Destroy the view, freeing the allocated memory
  409.    *   TscClose:              Closes the screen object
  410.    *   TTerminate:            Perform the clean-up for DV-Tools
  411.    */
  412.    TscErase (screen);
  413.    TdpDestroy (drawport);
  414.    TviDestroy (view);
  415.    TscClose (screen);
  416.    TTerminate ();
  417.   return (EXIT_OK);
  418. }
  419.